package com.meihua.shellapp.activity.wallet;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.meihua.shellapp.R;
import com.meihua.shellapp.base.BaseActivity;
import com.meihua.shellapp.base.MyApplication;
import com.meihua.shellapp.bean.IncomeBean;
import com.meihua.shellapp.databean.IncomeDataBean;
import com.meihua.shellapp.utils.DateUtils;
import com.meihua.shellapp.utils.ToastUtils;
import com.meihua.shellapp.utils.URL;

import butterknife.Bind;


/**
 * 我的钱包--收入详情界面
 */
public class IncomeDetailActivity extends BaseActivity {

    @Bind(R.id.tv_title)
    TextView tvTitle;
    @Bind(R.id.iv_top_left)
    ImageView mIVTopLeft;

    @Bind(R.id.ll_life)
    LinearLayout ll_life;//寿险
    @Bind(R.id.ll_nolife)
    LinearLayout ll_nolife;//非寿险

    @Bind(R.id.ll_standard)
    LinearLayout ll_standard;//标准店长

    @Bind(R.id.tv_time)
    TextView tv_time;//时间
    @Bind(R.id.tv_initial_service)
    TextView tv_initial_service;//首期
    @Bind(R.id.tv_renewal_service)
    TextView tv_renewal_service;//续期
    @Bind(R.id.tv_manage_interest)
    TextView tv_manage_interest;//管理利益
    @Bind(R.id.tv_bred_interest)
    TextView tv_bred_interest;//育成利益
    @Bind(R.id.tv_debit)
    TextView tv_debit;//其他加扣款
    @Bind(R.id.tv_deduction)
    TextView tv_deduction;//扣税金额
    @Bind(R.id.tv_actual_pay)
    TextView tv_actual_pay;//合 计


    @Bind(R.id.tv_totaxnt)
    TextView tv_totaxnt;//计税总额
    @Bind(R.id.tv_nolife_deduction)
    TextView tv_nolife_deduction;//扣税总额
    @Bind(R.id.tv_shouwag)
    TextView tv_shouwag;//应发服务费
    @Bind(R.id.tv_unfee)
    TextView tv_unfee;//不含税佣金
    @Bind(R.id.tv_vadtax)
    TextView tv_vadtax;//增值税
    @Bind(R.id.tv_tuition)
    TextView tv_tuition;//教育费及附加
    @Bind(R.id.tv_loctuit)
    TextView tv_loctuit;//地方教育附加
    @Bind(R.id.tv_citytax)
    TextView tv_citytax;//城建税
    @Bind(R.id.tv_taxome)
    TextView tv_taxome;//应纳税所得额
    @Bind(R.id.tv_indivmetax)
    TextView tv_indivmetax;//个人所得税
    @Bind(R.id.tv_online)
    TextView tv_online;//实发服务费

    private String id;
    private String type;

    @Override
    public int getLayoutId() {
        return R.layout.activity_income_detail;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        id = getIntent().getStringExtra("id");
        type = getIntent().getStringExtra("type");
        tvTitle.setVisibility(View.VISIBLE);
        tvTitle.setText("当月收入明细");
        mIVTopLeft.setVisibility(View.VISIBLE);
        mIVTopLeft.setOnClickListener(this);
    }

    /**
     * 绑定数据
     *
     * @param data
     */
    private void bindData(IncomeDataBean data) {
        if (type.equals("1")) {
            ll_life.setVisibility(View.VISIBLE);
            tv_time.setText(DateUtils.getInstance().getTimeYMDHM(data.getTime()));
            tv_initial_service.setText(data.getInitial_service());
            tv_renewal_service.setText(data.getRenewal_service());
            tv_manage_interest.setText(data.getManage_interest());
            tv_bred_interest.setText(data.getBred_interest());
            tv_debit.setText(data.getDebit());
            tv_deduction.setText(data.getDeduction());
            tv_actual_pay.setText(data.getActual_pay());
            if (data.getLevel().equals("2")) {
                ll_standard.setVisibility(View.VISIBLE);
            }
        } else {
            ll_nolife.setVisibility(View.VISIBLE);
            tv_totaxnt.setText(data.getTotaxnt());
            tv_nolife_deduction.setText(data.getDeduction());
            tv_shouwag.setText(data.getShouwag());
            tv_unfee.setText(data.getUnfee());
            tv_vadtax.setText(data.getVadtax());
            tv_tuition.setText(data.getTuition());
            tv_loctuit.setText(data.getLoctuit());
            tv_citytax.setText(data.getCitytax());
            tv_taxome.setText(data.getTaxome());
            tv_indivmetax.setText(data.getIndivmetax());
            tv_online.setText(data.getOnline());
        }
    }

    @Override
    public void createLoadData() {
        super.createLoadData();
        OkGo.<String>post(URL.getUrl().GETMONTHLISTDETAIL)
                .params("id", id)
                .params("type", type)
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        IncomeBean bean = MyApplication.getInstance().getBeanForJson(IncomeBean.class, response.body());
                        if (bean == null) {
                            return;
                        }
                        if (bean.getCode() == 1) {
                            bindData(bean.getData());
                        } else {
                            ToastUtils.getInstance().showToast(bean.getMsg());
                        }
                    }
                });
    }

}
